package ru.bank.paymentprocessing;

import io.restassured.RestAssured;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class PaymentControllerTest {
    @LocalServerPort
    int port;

    @BeforeEach
    void setUp() {
        RestAssured.baseURI = "http://localhost:" + port + "/api/payment/";
    }

    @Test
    void testProcessPaymentOnline_Success() {
        given()
                .when()
                .get("Online/100")
                .then()
                .statusCode(HttpStatus.OK.value())
                .contentType("text/plain;charset=UTF-8")
                .body(equalTo("Платеж успешно обработан для ONLINE"));
    }

    @Test
    void testProcessPaymentShop_Success() {
        given()
                .when()
                .get("Shop/100")
                .then()
                .statusCode(HttpStatus.OK.value())
                .contentType("text/plain;charset=UTF-8")
                .body(equalTo("Платеж успешно обработан для SHOP"));
    }

    @Test
    void testProcessPaymentShop_Error() {
        given()
                .when()
                .get("Online/10000")
                .then()
                .statusCode(HttpStatus.BAD_REQUEST.value())
                .contentType("text/plain;charset=UTF-8")
                .body(equalTo("Недостаточно средств для выполнения операции"));
    }
}
